package com.villaday.idf.adapter;

import android.app.Activity;
import android.content.Context;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.custom.foldtext.FoldTextView;
import com.villaday.idf.model.house_materialEntity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import byc.imagewatcher.MessagePicturesLayout;

/**
 * 首页动态列表
 */

public class FodderAdapter extends AbsRecyclerViewAdapter<house_materialEntity.BodyEntity> {
    private OnAdapterCallbackListener onAdapterCallbackListener;
    private View.OnClickListener onClickListener;
    private Activity activity;
    private MessagePicturesLayout.Callback mCallback;
    private final SimpleDateFormat format;
    private final SimpleDateFormat formatNew;

    public FodderAdapter(Context context, OnAdapterCallbackListener onAdapterCallbackListener, View.OnClickListener onClickListener, Activity activity) {
        super(context, R.layout.item_fodder, R.layout.item_page_loading,
                R.layout.item_page_bottom);
        this.onAdapterCallbackListener = onAdapterCallbackListener;
        this.onClickListener = onClickListener;
        this.activity = activity;
        format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        formatNew = new SimpleDateFormat("yyyy/MM/dd");
    }

    public FodderAdapter setPictureClickCallback(MessagePicturesLayout.Callback callback) {
        mCallback = callback;
        return this;
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, final house_materialEntity.BodyEntity d, int position) {
        // 一般来讲， ImageWatcher 需要占据全屏的位置
// 如果是透明状态栏，你需要给ImageWatcher标记 一个偏移值，以修正点击ImageView查看的启动动画的Y轴起点的不正确
// 配置error图标 如果不介意使用lib自带的图标，并不一定要调用这个API
//设置指示器（默认小白点）
//设置指示器颜色
// 长按图片的回调，你可以显示一个框继续提供一些复制，发送等功能
//调用show方法前，请先调用setLoader 给ImageWatcher提供加载图片的实现


        try {
            holder.bindSimpleDraweeView(R.id.sdv_head, d.getMerchant().getHeadImageURL())
                    .bindTextView(R.id.tv_name, d.getMerchant().getNickName())
                    .bindTextView(R.id.tv_time, formatNew.format(format.parse(d.getCreateTime())))
                    //.bindTextView(R.id.tv_time,d.getTitle())

                    .setViewVisible(R.id.tv_erweima, d.getEnablePoster()==0? View.GONE : View.VISIBLE)
                    .setViewVisible(R.id.tv_Save, d.getSaveMaterial()==0? View.GONE : View.VISIBLE)
                    .setViewVisible(R.id.tv_share1, d.getForward()==0? View.GONE : View.VISIBLE)

                    .setViewSelected(R.id.img_collect, d.isFavorite())
                    .setClickListenerAndTag(R.id.tv_Save, onClickListener, position)
                    .setClickListenerAndTag(R.id.img_collect, onClickListener, position)
                    .setClickListenerAndTag(R.id.tv_erweima, onClickListener, position)
                    .setClickListenerAndTag(R.id.tv_share1, onClickListener, position);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        FoldTextView ftv = (FoldTextView) holder.getView(R.id.ftv);
        ftv.setText(d.getAdWord());
        MessagePicturesLayout lPictures = (MessagePicturesLayout) holder.getView(R.id.l_pictures);
        lPictures.setCallback(mCallback);
        if (d.getMaterialType() == 1) {//为海报
            List<String> url = new ArrayList<>();
            url.add(d.getPoster());
            lPictures.set(url, url);

        } else {
            lPictures.set(d.getPicList(), d.getPicList());

        }


        //Utils.fitsSystemWindows(isTranslucentStatus, findViewById(R.id.v_fit));
    }


}
